<template>
  <div class="notice-config">
    <el-card>
      <div slot="header">买手公告配置</div>
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
        <el-form-item label="标题：" prop="title">
          <el-input v-model="ruleForm.title" />
        </el-form-item>
        <el-form-item label="公告详情：" prop="content">
          <el-input
            v-model="ruleForm.content"
            type="textarea"
            :rows="4"
            placeholder="请输入内容"
            autosize
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card style="margin-top: 10px;">
      <div slot="header">商家公告配置</div>
      <el-form ref="storeRuleForm" :model="storeRuleForm" :rules="storeRules" label-width="100px">
        <el-form-item label="标题：" prop="title">
          <el-input v-model="storeRuleForm.title" />
        </el-form-item>
        <el-form-item label="公告详情：" prop="content">
          <el-input
            v-model="storeRuleForm.content"
            type="textarea"
            :rows="4"
            placeholder="请输入内容"
            autosize
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitStoreForm('storeRuleForm')">立即修改</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
// import ckEditor from '@/components/_ckEditor'
import { getBuyerAffiche, updateBuyerAffiche, getSellerAffiche, updateSellerAffiche } from '@/api/user'
export default {
  // components: {
  //   ckEditor
  // },
  data() {
    return {
      ruleForm: {},
      rules: {},
      storeRuleForm: {},
      storeRules: {}
    }
  },
  mounted() {
    this.getBuyerAffiche()
    this.getSellerAffiche()
  },
  methods: {
    getBuyerAffiche() {
      getBuyerAffiche().then(res => {
        this.ruleForm = res
      })
    },
    getSellerAffiche() {
      getSellerAffiche().then(res => {
        this.storeRuleForm = res
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateBuyerAffiche(this.ruleForm).then(res => {
            this.$message({
              type: 'success',
              message: '修改成功!'
            })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submitStoreForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateSellerAffiche(this.storeRuleForm).then(res => {
            this.$message({
              type: 'success',
              message: '修改成功!'
            })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>
<style lang="scss">
.notice-config {
  .el-card {

  }
}
</style>

